package com.thor.palmmall.dao.banlancebill;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.balancebill.BanlanceBill;

public class BanlanceBillConverter  implements Converter<PBanlanceBill,BanlanceBill >{
  private static BanlanceBillConverter instance;
  public static BanlanceBillConverter getInstance() {
    if (instance == null) {
      instance = new BanlanceBillConverter();
    }
    return instance;
  }
  
  @Override
  public BanlanceBill convert(PBanlanceBill source) {
    if (source == null) {
      return null;
    }
    BanlanceBill target = new BanlanceBill();
    target.inject(source);
    target.setBillNo(source.getBillNo());
    target.setStore(source.getStore());
    target.setTenant(source.getTenant());
    target.setContract(source.getContract());
    target.setPayTotal(source.getPayTotal());
    target.setPayedTotal(source.getPayedTotal());
    target.setUnpayedTotal(source.getUnpayedTotal());
    target.setBillState(source.getBillState());
    target.setAttachmentId(source.getAttachmentId());
    target.setBillSettle(source.getBillSettle());
    target.setLegalName(source.getLegalName());
    target.setTaxCode(source.getTaxCode());
    target.setLegalPersion(source.getLegalPersion());
    target.setAddress(source.getAddress());
    target.setPhone(source.getPhone());
    target.setContractType(source.getContractType());
    if(source.getDetails() != null && source.getDetails().size() > 0){
        target.getDetails()
        .addAll(ConverterUtil.convert(source.getDetails(), new BanlanceBillDetailConvert()));
    }
    return target;
  }

}
